package com.ruoyi.car.controller.carmanage;

import com.car.pojo.TbCarScrap;
import com.ruoyi.car.service.carmanage.TbCarScrapService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
*车载报废信息Controller
*   @author 仲晓天
*/

@Controller
@RequestMapping("carmanage/scrap")
public class TbCarScrapController extends BaseController {

    @Autowired
    private TbCarScrapService tbScrapService;

    private String prefix = "carmanage/scrap";

    @RequiresPermissions("carmanage:scrap:view")
    @GetMapping()
    public String scrap()
    {
        return prefix + "/scrap";
    }



    @RequestMapping(value = "/test",method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult test(String vid){
        System.out.println(vid);
        return success(vid);
    }





    /**
     * 查询车辆报废表
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbCarScrap tbCarScrap){
        startPage();
        System.out.println("---------------"+tbCarScrap.toString());
        List<TbCarScrap> tbCarScraps =  this.tbScrapService.selectTbScrapList(tbCarScrap.getCarId(),tbCarScrap.getRecycleCrditCode());
        return getDataTable(tbCarScraps);
    }



    /**
     * 新增车辆报废表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆报废
     */
    @PostMapping("/scrapInsert")
    @ResponseBody
    public AjaxResult scrapInsert(TbCarScrap tbCarScrap){
        return toAjax(tbScrapService.scrapInsert(tbCarScrap));
    }



    /**
     * 修改车辆报废表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbCarScrap tbCarScrap = tbScrapService.selectTbCarScrapById(id);
        mmap.put("tbCarScrap", tbCarScrap);
        return prefix + "/edit";
    }

    /**
     * 修改车辆报废信息
     */
    @PostMapping("/scrapUpdate")
    @ResponseBody
    public AjaxResult scrapUpdate(TbCarScrap tbCarScrap){
        return toAjax(tbScrapService.scrapUpdate(tbCarScrap));
    }


    /**
     * 删除车辆报废信息
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbScrapService.deleteTbCarScrapByIds(ids));
    }

}
